package com.logistics.dictionary.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.dictionary.entity.model.DictionarySave;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author zhiyu.fan
 * @since 2024-05-14
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_dictionary")
public class Dictionary implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String name;

    private String code;

    private Integer parentId;

    private String language;

    private String externalCode;

    private String createOrgCode;

    private String createDepCode;

    private String creator;

    private Date createTime;

    private String updater;

    private Date updateTime;

    public Dictionary(){

    }

    public Dictionary(DictionarySave save){
        this.id = StringUtils.isNotNull(save.getId()) ? Integer.parseInt(save.getId()) : null;
        this.name = save.getName();
        this.code = save.getCode();
        this.parentId = StringUtils.isNotNull(save.getParentId()) ? Integer.parseInt(save.getParentId()) : null;
        this.language = save.getLanguage();
        this.externalCode = save.getExternalCode();
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.creator = save.getCreator();
        this.createTime = DateUtils.stringToDateFormat(save.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        this.updater = save.getUpdater();
        this.updateTime = DateUtils.stringToDateFormat(save.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }

    public static Dictionary build(DictionarySave save){
        return new Dictionary(save);
    }
}
